{include file="header/index" /}
<div class="newContentBox">
    <!-- 分割部分 -->
    <div class="newListPart">
<!--        <div class="newTitleBox">-->
<!--            <span class="layui-inline newListTitle">申请列表</span>-->
<!--        </div>-->
        <form method="get" action="#" class="layui-form"  name="searchuser">
            <div class="newForm">
                <div class="newGroup">
                    <div class="newGroupInput">
                        <input type="text" value="" id="keyword" placeholder="请输入姓名|手机号" class="layui-input-search cover_layui_i"/>
                    </div>
                </div>
                <div class="newGroup newBtnBox">
                    <a id="search" class="newBtnSearch newBtnPrimary">搜索</a>
                </div>

            </div>
        </form>
        <div class="newTableBox">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>姓名</th>
                    <th>手机号</th>
                    <th>推荐人</th>
                    <th>身份证</th>
                    <th>现居住地址</th>
                    <th>申请时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <!--套数据 laypage-->
                <script id="list-template" type="text/html">
                    {{# for(var i=0;i<d.length;i++){  }}
                    <tr>
                        <td>{{d[i].username}}</td>
                        <td>{{d[i].phone}}</td>
                        <td>{{d[i].realname}}(账号:{{d[i].account}})</td>
                        <td>{{d[i].id_card}}</td>
                        <td>{{d[i].address}}</td>
                        <td>{{d[i].apply_time}}</td>
                        <td>
                            {{# if(d[i].apply_status==1){ }}
                            <span style="color: #DF0101;"> 待审核</span>
                            {{# }else if(d[i].apply_status==2){ }}
                            申请通过
                            {{# }else if(d[i].apply_status==3){ }}
                            申请驳回
                            {{# } }}
                            {{# if(d[i].apply_status==2 && d[i].sign_contract_status==1){ }}
                                   ,待签合同
                            {{# }else if(d[i].apply_status==2 && d[i].sign_contract_status==2){ }}
                                    ,已签合同
                            {{# }else if(d[i].apply_status==2 && d[i].sign_contract_status==3){ }}
                            ,合同作废
                            {{# } }}
                        </td>
                        <td>
                            {{# if(d[i].apply_status==1){ }}
                            <a class="layui-btn newBtnDefault" onclick="auditing({{d[i].id}})">审核</a>
                            {{# } }}
                            {{# if(d[i].sign_contract_status==2){ }}
                            <a class="layui-btn newBtnDefault" href="{{d[i].contract_content}}" target="view_window">电子合同</a>
                            {{# } }}
<!--                            {{# if(d[i].apply_status==2){ }}-->
<!--                            <a class="layui-btn newBtnDefault" onclick="uploads({{d[i].id}})">上传合同</a>-->
<!--                            <a class="layui-btn newBtnDefault" onclick="lookup({{d[i].user_id}})">查看合同</a>-->
<!--                            {{# } }}-->
                            <a class="layui-btn newBtnDefault" href='{:url("Employee/apply_detail")}?id={{d[i].id}}'>查看详情</a>
                        </td>
                    </tr>
                    {{# } }}
                </script>
                <tbody id="list-content"></tbody>
            </table>
            <!--用来存当前页码数-->
            <input type="hidden" value="1" id="curr_" />
            <div class="laypage">
                <div class="laypage_total">共<span id="total_number"></span>条数据&nbsp;&nbsp;<span id="allpage"></span></div>
                <div class="laypage_skip" id="AjaxPage"></div>
            </div>
        </div>

    </div>
    <!--权限控制-->
    <input type="hidden" id="power" value="{$examine}">
</div>

<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl;

    $.ajaxSetup({headers: {token: $.cookie('token'),company: $.cookie('company_id')}});
    function auditing(id) {
        var power = $("#power").val();
        if (power == '0'){
            layer.msg('您还没有审核的权限！',{icon:2,time:1500,shade: 0.1,});
            return false;
        }

        var html = '';
        html += '<form class="layui-form popBox" action="" method="post"  >';
        html += '<div class="popChoose">';
        html += '<div class="leftPop">处理状态</div>';
        html += '<div class="rightPop">';
        html += '<div class="selectBox">';
        html += '<select id="_orderStatus" class="layui-input cover_layui_i">';
        html += '<option value="">选择状态</option>';
        html += '<option value="1">申请通过</option>';
        html += '<option value="2">申请拒绝</option>';
        html += '</select>';
        html += '</div>';
        html += '</div>';
        html += '</div>';

        html += '<div class="popChoose">';
        html += '<div class="leftPop">备注</div>';
        html += '<div class="rightPop">';
        html += '<textarea placeholder="请输入内容" class="layui-textarea" id="remarks"></textarea>';
        html += '</div>';
        html += '</div>';

        html += '</form>';
        parent.layer.open({
            title: '推广申请审核',
            type: 1,
            area: ['823px', '490px'], //宽高
            fixed: false,
            shadeClose: true, //点击遮罩关闭
            content: html,
            btn: ['确认', '取消'],
            btnAlign: 'c',
            success: function (layero, index) {
                parent.form.render();

            },
            yes: function (index, layero) {

                var status = $(layero).find("#_orderStatus option:selected").val();
                var status_name = $(layero).find("#_orderStatus option:selected").text();
                var remarks = $(layero).find("#remarks").val();
                if (status == '') {
                    parent.layer.msg('请选择处理状态', {
                        time: 1000,
                        icon: 0
                    });
                    return false;
                }
                var data = {};
                data.id = id;
                data.status = status;
                data.remarks = remarks;
                data = JSON.stringify(data);
                $.post("{:config('api')}/Achievement/Dealer/auditing",data,function (flag) {
                    parent.layer.close(index);
                    if (flag.code < 0){
                        parent.layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                        return false;
                    }
                    Ajaxpage();
                    parent.layer.msg(flag.message,{icon:1,time:1500,shade: 0.1,});
                });
                parent.layer.close(index);
            },
            btn2: function (index, layero) {
                //按钮【按钮二】的回调
                // return false;//开启该代码可禁止点击该按钮关闭
            },
            cancel: function () {
                //右上角关闭回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });

    }
    //搜索表单
    $("#search").click(function () {
        Ajaxpage(1);
    })

    Ajaxpage();
    function Ajaxpage(curr){
        var loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
        $("#curr_").val(curr);
        var keyword = $('#keyword').val();
        var request_data = {};
        request_data.keyword = keyword;
        request_data.page = curr || 1;
        request_data = JSON.stringify(request_data);
        // 保存工单搜索sessionStorege
        var sessionData = {
            page: curr || 1,
            keyword: keyword,
        };
        var str = JSON.stringify(sessionData);
        sessionStorage.setItem('sessionData', str);
        sessionStorage.setItem('sessionUrl', '{:url("Employee/apply")}');
        $.post("{:config('api')}/Achievement/Dealer/applyList", request_data, function(data){
            layer.close(loadingFlag);
            var page = data.data.page;
            $("#total_number").text(page.total);
            data = data.data.data;
            if(data==''){
                $("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
            }else{
                var tpl = document.getElementById('list-template').innerHTML;
                laytpl(tpl).render(data, function(html){
                    document.getElementById('list-content').innerHTML = html;
                });
            }
            //分页
            laypage.render({
                elem: 'AjaxPage' //分页容器的id
                ,count: page.total //总条数
                ,limit: page.row //每页条数
                ,skin: '#1AB5B7' //自定义选中色值
                ,curr: curr || 1
                ,layout: ['prev', 'page', 'next', 'skip']
                //,skip: true //开启跳页
                ,jump: function(obj, first){
                    if(!first){
                        Ajaxpage(obj.curr)
                    }
                    $('#allpage').html('第'+ obj.curr +'页，共'+ page.total_page +'页');
                }
            });
        });
    }

    //跳转详情
    function jump(id){
        window.location.href="{:url('financial/examinedetails')}?id="+id;
    }

    //上传纸质合同
    function uploads(id){
        window.location.href="{:url('Employee/uploads')}?id="+id;
    }

    //申请轨迹
    function trajectory(id) {
        window.location.href="{:url('Employee/trajectory')}?id="+id;
    }

    //查看纸质合同
    function lookup(user_id){
        window.location.href="{:url('Employee/lists')}?user_id="+user_id;
    }
</script>
